<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" isELIgnored="false" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" type="text/css" href="../static/layui/css/layui.css">
</head>

<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加员工信息</legend>
</fieldset>
<div class="layui-form  layui-from-pane" action="" accept-charset="UTF-8" id="formdemo">




    <div class="layui-form-item">
        <label class="layui-form-label">员工ID</label>
        <div class="layui-input-block">
            <input type="text" name="id" autocomplete="off" placeholder="请输入员工编号" class="layui-input" value="${data.id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">员工名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" autocomplete="off" placeholder="请输入员工名称" class="layui-input" value="${data.name}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">员工年龄</label>
        <div class="layui-input-block">
            <input type="text" name="age" autocomplete="off" placeholder="请输入员工年龄" class="layui-input" value="${data.age}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="text" name="gender" autocomplete="off" placeholder="请输入员工性别" class="layui-input" value="${data.gender}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"> </label>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
            <select id="bg_id" name="departmentId" lay-verify="required"  lay-filter="business" class="select">
                <option value="${data.departmentId}" ></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"> </label>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">薪水</label>
        <div class="layui-input-block">
            <input type="text" name="salary" autocomplete="off" placeholder="请输入员工薪水" class="layui-input" value="${data.salary}">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-block">
            <input type="text" name="job" autocomplete="off" placeholder="请输入员工职位" class="layui-input" value="${data.job}">
        </div>
    </div>



    <div class="layui-form-item">
        <button class="layui-btn layui-btn-submit " lay-submit="" lay-filter="add" style="margin-left: 45%;" onsubmit="return false">提交</button>
    </div>

</div>

<script src="../static/layui/layui.js" charset="utf-8"></script>
<script src="../static/layui/layui.all.js" charset="utf-8"></script>

<script>


    layui.use(['form','layer'] ,function(){
        var
            form=layui.form,
            layer = layui.layer

        var index = parent.layer.getFrameIndex(window.name);



        layui.jquery.ajax({
            type:"get",
            url:'/Employee/getDepartment',  //从数据库查询返回的是个list
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            async: false,
            cache: false,
            success: function (data)
            {
                for(i=0;i<data.data.length;i++)
                {
                    layui.jquery('#bg_id').append(new Option(data.data[i].name,data.data[i].id));
                }
                form.render();//菜单渲染 把内容加载进去
            }
        })

        form.render();
        //监听提交
        form.on('submit(add)', function(data)
        {
            layui.jquery.ajax({
                url: "/Employee/editemployee",
                type: "POST",
                async: false,   //不要让它异步提交
                data:JSON.stringify(data.field),
                contentType: 'application/json;charset=utf-8',
                success: function (data) {
                    if(data.msg!='0'){
                        layer.alert("修改成功",{icon: 1,time:2000},function () {
                            layer.close(layer.index);
                            window.parent.location.reload();    //重新加载父页面，进行数据刷新
                        });
                    } else{
                        layer.alert("修改失败",{icon: 2,time:2000});
                    }
                }
            });
            return false;
        });

    });
</script>

</body>
</html>

